package com.mnsq.common.bean.document;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.mnsq.common.bean.enums.StatusEnum;
import com.mnsq.common.bean.enums.SubjectType;
import lombok.Data;
import lombok.experimental.Accessors;
import matrix.module.based.serializer.DateTimeSerializer;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * 经过审核的信息
 *
 * @author 周俭
 */
@Data
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Document(collection = "subject")
public class SubjectMg extends BaseDoc{

    public SubjectMg() {
    }

    /**
     * 标题
     */
    @NotNull
    @TextIndexed
    private String title;
    /**
     * 类型
     *
     * @see SubjectType
     */
    private String type;
    /**
     * 题目内容，markdown内容
     */
    @TextIndexed
    private String subject;
    /**
     * 题目内容，html内容
     */
    private String htmlSubject;
    /**
     * 文章内容/答案内容/主体信息
     */
    @NotNull
    @TextIndexed
    private String content;
    private String htmlContent;
    /**
     * 选项
     */
    private List<String> choices;
    /**
     * 正确答案
     */
    private List<String> rightChoice;
    /**
     * 修改次数
     */
    private Integer updateTimes;
    /**
     * TODO 暂定周期性统计  LTS 部署
     */
    private Integer readTimes;
    private Integer commentTimes;
    private Integer collectTimes;
    private Integer praiseTimes;
    private Integer shareTimes;
    /**
     * 开发语言类型id
     *
     * @SEE Category.id
     */
    private Long developLanguageId;
    /**
     * @see StatusEnum
     */
    private Integer status;
    /**
     * 内容唯一码
     */
    @NotNull
    @Indexed(unique = true)
    private String unique;

    /**
     * 保存用户昵称
     */
    private String userName;
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 保存用户头像小图片
     */
    private String userHeadPic;

    @JsonSerialize(using = DateTimeSerializer.class)
    private Date updateTime;

    @NotNull
    @JsonSerialize(using = DateTimeSerializer.class)
    private Date createTime;

    public void saveInit() {
        this.status = StatusEnum.STATUS_VALID.value;
        this.createTime = new Date();
        this.updateTime = new Date();
    }
}
